﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model TaoPortal.Areas.Admin.Models.FileManageModel
<ul class="breadcrumb" style="margin-bottom: 7px;">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">内容管理</a> <span class="divider">/</span></li>
    <li class="active">文件管理</li>
</ul>
<div class="row-fluid">
    <div class="span6">
        <div class="panel">
            <div class="panel-header clearfix">
                <h3 class="pull-left">文件分类</h3>
                <div class="pull-right" id="tbar">
                    <ul class="bui-bar button-group" id="bar8" role="toolbar" aria-disabled="false">
                    </ul>
                </div>
            </div>
            <div class="panel-body" id="ArtTree">
            </div>
        </div>
    </div>
    <div class="span18">
        <div class="panel">
            <div class="panel-header clearfix">
                <h3 class="pull-left">文件列表</h3>
                <div class="pull-right">
                    <button id="addArticleBtn" class="button button-small button-primary">上传文件</button>
                </div>
            </div>
            <div class="panel-body" id="grid">
                <form tabindex="0" class="form-horizontal" id="searchForm">
                    <div class="row-fluid show-grid">
                        <div class="span7">
                            <label class="control-label control-label-auto">文件名称：</label>
                            <div class="controls" style="height: 30px">
                                @Html.HiddenFor(x => x.Searcher.FClassID)
                                @Html.TextBoxFor(x => x.Searcher.FName, new { @class = "input-normal" })
                            </div>
                        </div>
                        <div class="span9" style="">
                            <label class="control-label control-label-auto">上传日期：</label>
                            <div class="controls" style="height: 30px">
                                @Html.TextBoxFor(x => x.Searcher.StartDate, new { @class = "calendar" }) - @Html.TextBoxFor(x => x.Searcher.EndDate, new { @class = "calendar" })
                            </div>
                        </div>
                        <div class="span3">
                            <button class="button button-small" id="btnSearch" type="submit">搜索</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var Overlay = BUI.Overlay
    var dialog = null;
    var tree = null;
    //日期控件
    BUI.use('bui/calendar', function (Calendar) {
        var datepicker = new Calendar.DatePicker({
            trigger: '.calendar',
            autoRender: true
        });
    });
    function AddClass() {
        dialog = new Overlay.Dialog({
            title: '文件管理->添加分类',
            width: 580,
            closeAction: 'destroy',
            height: 290,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:570px;height:180px" src="/Admin/FileManage/AddClass"></iframe>'
        });
        dialog.show();
    }
    function EditClass() {
        var selected = tree.getSelected();
        if (selected == null) {
            alert('请选择分类！');
            return false;
        }
        dialog = new Overlay.Dialog({
            title: '文件管理->编辑分类',
            width: 580,
            closeAction: 'destroy',
            height: 290,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:570px;height:180px" src="/Admin/FileManage/EditClass?id=' + selected.id + '"></iframe>'
        });
        dialog.show();
    }
    function CloseWin() {
        dialog.close();
    }
    function DelClass() {
        var selected = tree.getSelected();
        if (selected == null) {
            alert('请选择分类！');
            return false;
        }
        if (confirm('确认删除？')) {
            $.ajax({
                type: 'post',
                url: '/Admin/FileManage/DeleteClass',
                data: { id: selected.id },
                success: function (res) {
                    location.reload();
                }
            });
        }
    }
    function SubmitSuccess() {
        //alert('提交成功！');
        dialog.close();
        $('#btnSearch').trigger('click');
    }
    function DeleteFile(id) {
        if (confirm('确认删除？')) {
            $.ajax({
                type: 'post',
                url: '/Admin/FileManage/Delete',
                data: { id: id },
                success: function (res) {
                    $('#btnSearch').trigger('click');
                }
            });
        }
    }
    function DownloadFile(id) {
        window.open('/DeownloadFile/' + id);
    }
    var Toolbar = BUI.Toolbar;
    var g3 = new Toolbar.Bar({
        elCls: 'button-group',
        multipleSelect: true,
        defaultChildCfg: {
            elCls: 'button button-small',
            selectable: true //允许选中
        },
        children: [
          { content: '<i class="icon icon-plus"></i>', id: 'addBtn', handler: AddClass, elAttrs: { title: '增加' } },
          { content: '<i class="icon icon-edit"></i>', id: 'editBtn', handler: EditClass, elAttrs: { title: '编辑' } },
          { content: '<i class="icon icon-remove"></i>', id: 'delBtn', handler: DelClass, elAttrs: { title: '删除' } }
        ],
        render: '#tbar'
    });
    g3.render();

    $('#addArticleBtn').click(function () {
        dialog = new Overlay.Dialog({
            title: '文件管理->上传文件',
            width: 580,
            //closeAction: 'destroy',
            height: 390,
            //listeners: {
            //    closing: function (ev) {
            //        //debugger;
            //        //$('iframe', ev.target.get('view').get('tabContentEl')).attr('src', '');
            //        //return false;
            //    },
            //},
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:570px;height:273px" src="/Admin/FileManage/Upload"></iframe>'
        });
        dialog.show();
    })


    //文章分类
    BUI.use(['bui/tree', 'bui/data'], function (Tree, Data) {
        //数据缓冲类
        var store = new Data.TreeStore({
            url: '/Admin/FileManage/AjaxGetClass',
            autoLoad: true
        });

        tree = new Tree.TreeList({
            render: '#ArtTree',
            showLine: true,
            height: 300,
            store: store
        });
        tree.render();

        tree.on('itemclick', function (ev) {
            if (!ev.item.id)
                return false;
            $('#Searcher_FClassID').val(ev.item.id);
            $('#btnSearch').trigger('click');
        });
    });




    //列表
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '文件名称', width: 150, sortable: false, dataIndex: 'FName' },
      {
          title: '文件地址', width: 250, sortable: false, dataIndex: 'ID', renderer: function (value, obj) {
              return '<input type="text" style="width:232px" readonly="readonly" value="/File/' + value + '" />';
          }
      },
      { title: '类型', width: 70, sortable: false, dataIndex: 'FExtName' },
      { title: '大小', width: 70, sortable: false, dataIndex: 'FLength' },
      { title: '上传时间', width: 150, sortable: false, dataIndex: 'CreateTime' },
      {
          title: '操作', width: 80, sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="DeleteFile(\'' + value + '\')">删除</span><span class="grid-command" onclick="DownloadFile(\'' + value + '\')" >下载</span>';
          }
      }
    ];
          //加载列表
          var store = new Store({
              url: '/Admin/FileManage/AjaxGetList',
              proxy: {
                  limitParam: 'pageSize',
                  method: 'post'
              },
              autoLoad: true,
              pageSize: 10
          }),
          grid = new Grid.Grid({
              render: '#grid',
              loadMask: true,
              forceFit: true,
              plugins: [Grid.Plugins.AutoFit],
              columns: columns,
              store: store,
              bbar: {
                  pagingBar: true
              }
          });
          grid.render();
          //搜索
          var form = $('#searchForm')[0];
          $(form).on('submit', function (ev) {
              ev.preventDefault();
              var obj = BUI.FormHelper.serializeToObject(form);
              obj.pageIndex = 0;
              obj.start = 0;
              store.load(obj);
          });

</script>
